import Vue from "vue";
import VueRouter from "vue-router";


Vue.use(VueRouter);

const routes = [
	//访问 /,也跳转到login
	{
		path: '/',
		redirect: 'login' //重定向都login
	},
	//登录
	{
		path: '/login',
		name: 'login',
		component: () => import(/* webpackChunkName: "403" */ '../views/Login.vue')
	},
	{
		path: '/403',
		name: '403',
		component: () => import(/* webpackChunkName: "403" */ '../components/403.vue')
	},
	{
		path: '/index',
		name: 'index',
		component: () => import(/* webpackChunkName: "403" */ '../views/Index.vue'),
		children: [
			{
				path: "/home",
				name: "home",
				component: () => import(/* webpackChunkName: "user" */ '../views/home/index.vue')
			}, {
				path: "/system/user",
				name: "user",
				component: () => import(/* webpackChunkName: "user" */ '../views/user/User.vue')
			},
			{
				path: "/system/role",
				name: "role",
				component: () => import(/* webpackChunkName: "role" */ '../views/role/Role.vue')
			},
			{
				path: "/system/menu",
				name: "menu",
				component: () => import(/* webpackChunkName: "menu" */ '../views/menu/Menu.vue')
			},
			{
				path: "/system/dict",
				name: "dict",
				component: () => import(/* webpackChunkName: "dict" */ '../views/dict/Dict.vue')
			},
			{
				path: "/system/form",
				name: "form",
				component: () => import(/* webpackChunkName: "form" */ '../views/form/Form.vue')
			},
			{
				path: "/system/monitor",
				name: "monitor",
				component: () => import(/* webpackChunkName: "form" */ '../views/monitor/TimerJob.vue')
			}
		]
	},
];

const router = new VueRouter({
	// base: "/hh",
	linkActiveClass: "active",
	routes,
	mode: 'history',
});
router.afterEach(() => {
	document.title = '后台管理系统 - ';
})
/**
 * @description: 全局前置守卫
 * @param {*} to 要进入的路由对象
 * @param {*} from 离开的路由对象
 * @param {*} next() 传入的参数有四种情况，为空时执行下一个导航守卫方法；false时中断当前的导航；如果是个路径，就跳转到指定的路由；如果是个error实例，导航终止并把实例传给 router.onError()回调
 * @return {*}
 */
// router.beforeEach((to, from, next) => {
//   console.log(from);
//   document.title = to.meta.title;
//   next();
// });
export default router;
